# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : 组合提示词-使用 PipelinePrompt.py
# @Author: dongguangwen
# @Date  : 2025-03-23 17:53
from langchain_core.prompts import PipelinePromptTemplate, PromptTemplate

full_template = """{introduction}

{example}

{start}"""
full_prompt = PromptTemplate.from_template(full_template)
print(full_prompt)

introduction_template = """You are impersonating {person}."""
introduction_prompt = PromptTemplate.from_template(introduction_template)
print(introduction_prompt)

example_template = """Here's an example of an interaction:

Q: {example_q}
A: {example_a}"""
example_prompt = PromptTemplate.from_template(example_template)
print(example_prompt)

start_template = """Now, do this for real!

Q: {input}
A:"""
start_prompt = PromptTemplate.from_template(start_template)
print(start_prompt)

input_prompts = [
    ("introduction", introduction_prompt),
    ("example", example_prompt),
    ("start", start_prompt),
]
print(input_prompts)

pipeline_prompt = PipelinePromptTemplate(
    final_prompt=full_prompt, pipeline_prompts=input_prompts
)
print(pipeline_prompt)

ret = pipeline_prompt.input_variables
print(ret)

res = pipeline_prompt.format(
        person="Elon Musk",
        example_q="What's your favorite car?",
        example_a="Tesla",
        input="What's your favorite social media site?",
    )
print(res)

"""
input_variables=['example', 'introduction', 'start'] input_types={} partial_variables={} template='{introduction}\n\n{example}\n\n{start}'
input_variables=['person'] input_types={} partial_variables={} template='You are impersonating {person}.'
input_variables=['example_a', 'example_q'] input_types={} partial_variables={} template="Here's an example of an interaction:\n\nQ: {example_q}\nA: {example_a}"
input_variables=['input'] input_types={} partial_variables={} template='Now, do this for real!\n\nQ: {input}\nA:'
[('introduction', PromptTemplate(input_variables=['person'], input_types={}, partial_variables={}, template='You are impersonating {person}.')), ('example', PromptTemplate(input_variables=['example_a', 'example_q'], input_types={}, partial_variables={}, template="Here's an example of an interaction:\n\nQ: {example_q}\nA: {example_a}")), ('start', PromptTemplate(input_variables=['input'], input_types={}, partial_variables={}, template='Now, do this for real!\n\nQ: {input}\nA:'))]
input_variables=['example_q', 'input', 'person', 'example_a'] input_types={} partial_variables={} final_prompt=PromptTemplate(input_variables=['example', 'introduction', 'start'], input_types={}, partial_variables={}, template='{introduction}\n\n{example}\n\n{start}') pipeline_prompts=[('introduction', PromptTemplate(input_variables=['person'], input_types={}, partial_variables={}, template='You are impersonating {person}.')), ('example', PromptTemplate(input_variables=['example_a', 'example_q'], input_types={}, partial_variables={}, template="Here's an example of an interaction:\n\nQ: {example_q}\nA: {example_a}")), ('start', PromptTemplate(input_variables=['input'], input_types={}, partial_variables={}, template='Now, do this for real!\n\nQ: {input}\nA:'))]
['example_q', 'input', 'person', 'example_a']
You are impersonating Elon Musk.

Here's an example of an interaction:

Q: What's your favorite car?
A: Tesla

Now, do this for real!

Q: What's your favorite social media site?
A:
"""
